package com.atguigu.springboot.comtroller;

import com.atguigu.springboot.entity.Employee;
import com.atguigu.springboot.service.IEmployeeService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author : wenchao.long
 * @date : Created in 2020/11/26 10:19 周四
 * @description :
 */
@RestController()
@RequestMapping("/employee")
@AllArgsConstructor
public class EmployeeController {

    private final IEmployeeService employeeService;

    @GetMapping()
    public Employee getById(@RequestParam("id") Integer id) {
        return employeeService.getById(id);
    }

    @PutMapping()
    public Employee insert(@RequestBody Employee employee) {
        employeeService.insert(employee);
        return employee;
    }

    @PostMapping()
    public Employee update(@RequestBody Employee employee) {
        return employeeService.update(employee);
    }

    @DeleteMapping()
    public void delete(@RequestParam("id") Integer id) {
        employeeService.deleteById(id);
    }

    @GetMapping("/name")
    public Employee getByName(@RequestParam("name") String name) {
        return employeeService.getByName(name);
    }
}
